/**
 * @author: htqw
 * @description: connect to mysql
 */

/**
 * 
 * @param {import('../../dist/mysql.cjs.js').Config} config 
 * @param {import('mysql2')} mysql2 
 */

export default function connect(config, mysql2) {
    /**
     * @type {import('mysql2').ConnectionOptions}
     */
    const options = {
        rowsAsArray: true
    }
    for (const i in config) {
        options[i] = config[i]
    }
    const connection = mysql2.createConnection(config)
    connection.connect((err) => {
        if (err) {
            console.error(err)
            throw err
        }
    })
    return connection
}